package com.etoak.common.core.vo;

import com.etoak.common.core.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO<T> {

    private Integer code;

    private String message;

    private T data;

    /**
     * 默认执行成功之后调用 {"code": 200, "message": "执行成功", "data": null}
     */
    public static <T> ResultVO<T> success() {
        return success(null);
    }

    /**
     * 执行成功之后调用 {"code": 200, "message": "执行成功", "data": null | {} | [] | "" | "aaaa"}
     */
    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }

    public static <T> ResultVO<T> failed() {
        return failed(ResultEnum.SYSTEM_ERROR);
    }

    public static <T> ResultVO<T> failed(ResultEnum resultEnum) {
        return failed(resultEnum.getCode(), resultEnum.getMessage());
    }

    public static <T> ResultVO<T> failed(int code, String message) {
        return new ResultVO<>(code, message, null);
    }
}
